package test.wrc.com.app;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

public class UIActivity extends BaseActivity {

    TextView textView;
    Button button;
    EditText editText;
    ImageView imageView;

    ProgressBar progressBar1, progressBar2;
    Button buttonProgressBar1, buttonProgressBar2;


    Button buttonAlertDialog, buttonProgressDialog;

    Button linearLayout;
    Button relativeLayout;
    Button frameLayout;
    Button tableLayout;
    Button percentFrameLayout;
    Button percentRelativeLayout;
    Button listView;
    Button recyclerView;

    Button gridView;

    ImageButton imageButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ui);
        ActionBar actionBar = getSupportActionBar();//隐藏标题
        if (actionBar != null) {
            actionBar.hide();
        }
        textView = (TextView) findViewById(R.id.textView);
        textView.setOnClickListener(this);
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(this);
        editText = (EditText) findViewById(R.id.editText);
        editText.setOnClickListener(this);
        imageView = (ImageView) findViewById(R.id.imageView);
        imageView.setOnClickListener(this);

        progressBar1 = (ProgressBar) findViewById(R.id.progressBar1);
        progressBar1.setOnClickListener(this);
        buttonProgressBar1 = (Button) findViewById(R.id.buttonProgressBar1);
        buttonProgressBar1.setOnClickListener(this);
        progressBar2 = (ProgressBar) findViewById(R.id.progressBar2);
        progressBar2.setOnClickListener(this);
        buttonProgressBar2 = (Button) findViewById(R.id.buttonProgressBar2);
        buttonProgressBar2.setOnClickListener(this);

        buttonAlertDialog = (Button) findViewById(R.id.buttonAlertDialog);
        buttonAlertDialog.setOnClickListener(this);
        buttonProgressDialog = (Button) findViewById(R.id.buttonProgressDialog);
        buttonProgressDialog.setOnClickListener(this);

        linearLayout = (Button) findViewById(R.id.linearLayout);
        linearLayout.setOnClickListener(this);
        relativeLayout = (Button) findViewById(R.id.relativeLayout);
        relativeLayout.setOnClickListener(this);
        frameLayout = (Button) findViewById(R.id.frameLayout);
        frameLayout.setOnClickListener(this);
        tableLayout = (Button) findViewById(R.id.tableLayout);
        tableLayout.setOnClickListener(this);
        percentFrameLayout = (Button) findViewById(R.id.percentFrameLayout);
        percentFrameLayout.setOnClickListener(this);
        percentRelativeLayout = (Button) findViewById(R.id.percentRelativeLayout);
        percentRelativeLayout.setOnClickListener(this);

        listView = (Button) findViewById(R.id.listView);
        listView.setOnClickListener(this);
        recyclerView = (Button) findViewById(R.id.recyclerView);
        recyclerView.setOnClickListener(this);

        gridView = (Button) findViewById(R.id.gridView);
        gridView.setOnClickListener(this);

        imageButton = (ImageButton) findViewById(R.id.imageButton);
        imageButton.setOnClickListener(this);


        findViewById(R.id.button).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Toast.makeText(UIActivity.this, "长按事件OnLongClickListener", Toast.LENGTH_SHORT).show();
                return false;
            }
        });
    }


    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {
            case R.id.textView:
                Toast.makeText(this, textView.getText(), Toast.LENGTH_SHORT).show();
                break;
            case R.id.button:
                Toast.makeText(this, "Button", Toast.LENGTH_SHORT).show();
                break;
            case R.id.editText:
                Toast.makeText(this, editText.getText(), Toast.LENGTH_SHORT).show();
                break;
            case R.id.imageView:
                Toast.makeText(this, "ImageView", Toast.LENGTH_SHORT).show();
                imageView.setImageResource(R.mipmap.ic_launcher_round);
                break;
            case R.id.buttonProgressBar1:
                Toast.makeText(this, "ProgressBar:" + progressBar1.getVisibility(), Toast.LENGTH_SHORT).show();
                if (progressBar1.getVisibility() == View.GONE) {//不可见
                    progressBar1.setVisibility(View.INVISIBLE);
                } else if (progressBar1.getVisibility() == View.INVISIBLE) {//不可见占位置
                    progressBar1.setVisibility(View.VISIBLE);
                } else if (progressBar1.getVisibility() == View.VISIBLE) {//可见的
                    progressBar1.setVisibility(View.GONE);
                }
                break;
            case R.id.buttonProgressBar2:
                Toast.makeText(this, "ProgressBar:" + progressBar2.getProgress(), Toast.LENGTH_SHORT).show();
                progressBar2.setProgress(progressBar2.getProgress() + 10);
                break;
            case R.id.buttonAlertDialog:
                Toast.makeText(this, "AlertDialog", Toast.LENGTH_SHORT).show();
                AlertDialog.Builder dialog = new AlertDialog.Builder(this);
                dialog.setTitle("标题");
                dialog.setMessage("内容：AlertDialog");
                dialog.setCancelable(false);
                dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(UIActivity.this, "确定", Toast.LENGTH_SHORT).show();
                    }
                });
                dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(UIActivity.this, "取消", Toast.LENGTH_SHORT).show();
                    }
                });
                dialog.show();
                break;
            case R.id.buttonProgressDialog:
                Toast.makeText(this, "ProgressDialog", Toast.LENGTH_SHORT).show();
                ProgressDialog progressDialog = new ProgressDialog(this);
                progressDialog.setTitle("标题ProgressDialog");
                progressDialog.setMessage("Loading...");
                progressDialog.setCancelable(true);//true能返回 false 不能返回
                progressDialog.show();
                //                progressDialog.dismiss();//关闭对话框
                break;
            case R.id.linearLayout:
                Toast.makeText(this, "LinearLayoutActivity", Toast.LENGTH_SHORT).show();
                intent = new Intent();
                intent.setClass(this, LinearLayoutActivity.class);
                startActivity(intent);
                break;
            case R.id.relativeLayout:
                Toast.makeText(this, "RelativeLayoutActivity", Toast.LENGTH_SHORT).show();
                intent = new Intent();
                intent.setClass(this, RelativeLayoutActivity.class);
                startActivity(intent);
                break;
            case R.id.frameLayout:
                Toast.makeText(this, "FrameLayoutActivity", Toast.LENGTH_SHORT).show();
                intent = new Intent();
                intent.setClass(this, FrameLayoutActivity.class);
                startActivity(intent);
                break;
            case R.id.tableLayout:
                Toast.makeText(this, "TableLayoutActivity", Toast.LENGTH_SHORT).show();
                intent = new Intent();
                intent.setClass(this, TableLayoutActivity.class);
                startActivity(intent);
                break;
            case R.id.percentFrameLayout:
                Toast.makeText(this, "PercentFrameLayoutActivity", Toast.LENGTH_SHORT).show();
                intent = new Intent();
                intent.setClass(this, PercentFrameLayoutActivity.class);
                startActivity(intent);
                break;
            case R.id.percentRelativeLayout:
                Toast.makeText(this, "PercentRelativeLayoutActivity", Toast.LENGTH_SHORT).show();
                intent = new Intent();
                intent.setClass(this, PercentRelativeLayoutActivity.class);
                startActivity(intent);
                break;
            case R.id.listView:
                Toast.makeText(this, "ListViewActivity", Toast.LENGTH_SHORT).show();
                intent = new Intent();
                intent.setClass(this, ListViewActivity.class);
                startActivity(intent);
                break;
            case R.id.recyclerView:
                Toast.makeText(this, "RecyclerViewActivity", Toast.LENGTH_SHORT).show();
                intent = new Intent();
                intent.setClass(this, RecyclerViewActivity.class);
                startActivity(intent);
                break;

            case R.id.gridView:
                Toast.makeText(this, "GridActivity", Toast.LENGTH_SHORT).show();
                intent = new Intent();
                intent.setClass(this, GridActivity.class);
                startActivity(intent);
                break;
            case R.id.imageButton:
                Toast.makeText(this, "ImageButton", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
